package com.zjdiepu.www.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang.StringUtils;

/**
 * 过滤html标签
 * @author xiongxiaotun
 *
 */
public class HtmlUtil {
	private final static String regxpForHtml = "<([^>]*)>"; // 过滤所有以<开头以>结尾的标签   

	/**
	 * 过滤html标签
	 * 
	 * @param remarks
	 */
	public static String filterHtml(String remarks) {
		if(StringUtils.isBlank(remarks)) {
			return "";
		}
		Pattern pattern = Pattern.compile(regxpForHtml);
		Matcher matcher = pattern.matcher(remarks);
		StringBuffer sb = new StringBuffer();
		boolean result1 = matcher.find();
		while (result1) {
			matcher.appendReplacement(sb, "");
			result1 = matcher.find();
		}
		matcher.appendTail(sb);
		return sb.toString().replaceAll("&nbsp;", "");
	}
}
